package cn.exempale.mscapplication.utils;

import android.util.Log;

import org.apache.http.conn.ssl.AllowAllHostnameVerifier;

import cn.exempale.mscapplication.constant.BaseConstant;
import okhttp3.OkHttpClient;
import okhttp3.Request;

/**
 * retrofit 统一header 设置
 */
public final class RetrofitUtils {

    private static final String TAG = "RetrofitUtils";

    /**
     * file header
     */
    public static OkHttpClient fileClient() {
        return new OkHttpClient.Builder()
                .addInterceptor(chain -> {
                    Request request = chain.request()
                            .newBuilder()
                            .addHeader(BaseConstant.CONTENT_TYPE, BaseConstant.FILE_TYPE)
                            .build();
                    return chain.proceed(request);
                })
                .hostnameVerifier(new AllowAllHostnameVerifier())
                .build();
    }

    /**
     * normal header
     */
    public static OkHttpClient normalClient() {
        return new OkHttpClient.Builder()
                .addInterceptor(chain -> {
                    Request request = chain.request()
                            .newBuilder()
                            .addHeader(BaseConstant.CONTENT_TYPE, BaseConstant.NORMAL_TYPE)
                            .build();
                    return chain.proceed(request);
                })
                .hostnameVerifier(new AllowAllHostnameVerifier())
                .build();
    }
}
